﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using BLL;
using Model;

namespace EstateappraisalApi.Controllers
{
    /// <summary>
    /// 询价记录
    /// </summary>
    public class InquiryController : ApiController
    {
        // GET api/inquiry

        InquiryBLL bll = new InquiryBLL();

        /// <summary>
        /// 显示所有询价记录
        /// </summary>
        /// <returns></returns>
        public IEnumerable<Inquiry> Get()
        {
            return bll.ShowInquiry();
        }

        // GET api/department/5
        /// <summary>
        /// 查询某个项目的询价记录
        /// </summary>
        /// <param name="department_Id"></param>
        /// <returns></returns>
        public List<Inquiry> Get(string projectNumber)
        {
            return bll.ShowInquiry(projectNumber);
        }

        /// <summary>
        /// 添加询价记录
        /// </summary>
        /// <param name="value"></param>
        public int Post([FromBody]Inquiry mod)
        {
            mod.inquiry_CreatePeople = "1";
            mod.inquiry_CreateTime = DateTime.Now;
            if (bll.AddInquiry(mod))
            {
                return 1;
            }
            else
            {
                return 0;
            }
        }

        // PUT api/department/5
        /// <summary>
        /// 修改询价记录
        /// </summary>
        /// <param name="id"></param>
        /// <param name="value"></param>
        public int Put([FromBody]Inquiry m)
        {
            m.inquiry_CreatePeople = "1";
            m.inquiry_CreateTime = DateTime.Now;
            if (bll.UpdInquiry(m, m.inquiry_Id))
            {
                return 1;
            }
            else
            {
                return 0;
            }

        }


        /// <summary>
        /// 删除询价记录
        /// </summary>
        /// <param name="id"></param>
        [HttpDelete]
        public int Delete(int id)
        {
            Inquiry m = new Inquiry();
            m.inquiry_Id = id;
            if (bll.DelInquiry(m))
            {
                return 1;
            }
            else
            {
                return 0;
            }

        }
    }
}
